import { createStore } from 'vuex'
interface state{
  userInfo:object,
  isToken:boolean
}
const state:state = {
  userInfo:{},
  isToken:false
}

const mutations = {
  setUserInfo(state,payload):void{
    state.userInfo = payload
  },
  changeUserName(state,payload):void{
    state.userInfo.userName = payload.username
  },
  changeUserAvatar(state,payload):void{
    state.userInfo.avatar = payload.avatar
  },
  setToken(state,payload):void {
    if(payload) state.isToken = true
  }
}

const actions = {
  addNumber(context, number) {
    context.commit('add_num', number)
  }
}

const getters = {
  getNumbers(state) {
    return state.numbers
  }
}

const store = createStore({
  state,
  mutations,
  actions,
  getters
})

export default store
